﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teigha.Core;
using Teigha.TD;

namespace YJKCopyModel.Basic
{
    public class TeighaServices : IDisposable
    {
        private static TeighaServices m_appServices;

        private ExSystemServices m_TeighaExSysServices;

        private ExHostAppServices m_HostAppServices;

        public static TeighaServices TeighaServicesInstance
        {
            get
            {
                if (TeighaServices.m_appServices == null)
                {
                    TeighaServices.m_appServices = new TeighaServices();
                }
                return TeighaServices.m_appServices;
            }
        }

        public ExHostAppServices HostAppServices
        {
            get
            {
                return this.m_HostAppServices;
            }
        }

        private TeighaServices()
        {
        }

        public bool InitTeighaService(bool bAttach)
        {
            if (bAttach)
            {
                //if(m_TeighaExSysServices!=null)
                this.m_TeighaExSysServices = new ExSystemServices();
                // if(m_TeighaExSysServices!=null)
                TD_Db.odInitialize(this.m_TeighaExSysServices);
                // if(m_HostAppServices!=null)
                this.m_HostAppServices = new ExHostAppServices();
            }
            else
            {
                this.m_TeighaExSysServices.Dispose();
                this.m_HostAppServices.Dispose();
                TD_Db.odUninitialize();
            }
            return true;
        }

        public void Dispose()
        {
            m_appServices.InitTeighaService(false);
        }
    }
}
